//
//  FZHomeStatusListCell.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/24/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

class FZHomeStatusListCell: UITableViewCell {
    
    //MARK:==========================属性==========================
    var status: FZHomeStatusViewModel?{
        didSet{
            if status?.status?.retweeted_status != nil {
                
                retweetView.status = status
            }else{
                
                 retweetView.status = nil 
            }
            
            originalView.status = status
            toolBarView.status = status
        }
    }
    

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        setupLayout()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK:==========================加载界面==========================
    func setupUI(){
        
        contentView.addSubview(backView)
        backView.addSubview(originalView)
        backView.addSubview(toolBarView)
        backView.addSubview(retweetView)
    }
    func setupLayout() {
        
        backView.snp_makeConstraints { (make) in
        
            make.top.leading.trailing.equalTo(0)
            make.bottom.equalTo(toolBarView.snp_bottom).offset(PADDING)
        }
        originalView.snp_makeConstraints { (make) in
            
            make.top.leading.trailing.equalTo(backView)
        }
        
        retweetView.snp_makeConstraints { (make) in
            
            make.top.equalTo(originalView.snp_bottom).offset(0)
            make.leading.equalTo(PADDING)
            make.trailing.equalTo(-PADDING)
            
        }

        toolBarView.snp_makeConstraints { (make) in
            
            make.top.equalTo(retweetView.snp_bottom)
            make.leading.trailing.equalTo(backView)
            make.height.equalTo(30)
        }
        contentView.snp_makeConstraints { (make) in
            
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(backView.snp_bottom)
        }
        
    }
    
    //MARK:==========================懒加载==========================
    
    private lazy var originalView: FZHomeStatusOriginalView = FZHomeStatusOriginalView()
    private lazy var retweetView: FZHomeStatusRetweetView = FZHomeStatusRetweetView()
    private lazy var toolBarView: FZHomeStatusToolBarView = FZHomeStatusToolBarView()
    private lazy var backView: UIView = {
        let vi = UIView()
        vi.backgroundColor = TheTableColor
        return vi
    }()
    
    
}
